package com.cjg.array;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArraySet;

public class setDemo {
    public static void main(String[] args) {
        //java.util.ConcurrentModificationException
        /**
         *
         *解决方案1 set 继承collections
         * 解决方案2  JUc java.util.concurrent.CopyOnWriteArraySet;
         */
      Set<Object> set = Collections.synchronizedSet(new HashSet<>());
//        Set<Object> set = new CopyOnWriteArraySet<>();
        for (int i = 0; i <20 ; i++) {
            new Thread(()->{
                set.add(UUID.randomUUID().toString().substring(0,5));
                System.out.println(set);
            },String.valueOf(i)).start();
        }
    }
}
